package com.dom.domweb.modular.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.dom.common.enums.SysCodeTblEnum;
import com.dom.common.model.vo.basic.*;
import com.dom.common.utils.BeanUtil;
import com.dom.domweb.consumer.BasicStorConsumer;
import com.dom.domweb.consumer.BasicSuppConsumer;
import com.dom.domweb.consumer.BasicSysCodeConsumer;
import com.dom.domweb.dao.entity.TStorInfo;
import com.dom.domweb.dao.entity.TSuppInfo;
import com.dom.domweb.dao.entity.TSysCodeTbl;
import com.dom.domweb.dao.service.ITStorInfoService;
import com.dom.domweb.dao.service.ITSuppInfoService;
import com.dom.domweb.dao.service.ITSysCodeTblService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Description 基础信息服务service
 * @Author xllei
 * @Date 2018/11/13 下午9:38
 * @Version 1.0
 **/
@Service
public class BasicService {
    @Autowired
    private ITSysCodeTblService sysCodeTblService;
    @Autowired
    private ITStorInfoService storInfoService;
    @Autowired
    private ITSuppInfoService suppInfoService;

    /**
     * 查询仓库信息列表
     * @param memCode
     * @return
     */
    public List<StorInfo> getStorInfoList(int memCode) {
        List<TStorInfo> records = storInfoService.getStorList(memCode);
        List<StorInfo> storInfos = new ArrayList<>();
        records.forEach(entity->{
            StorInfo info = buildPropertites(entity);
            storInfos.add(info);
        });
        return storInfos;
    }

    private StorInfo buildPropertites(TStorInfo entity){
        StorInfo storInfo = new StorInfo();
        BeanUtils.copyProperties(entity, storInfo);
        storInfo.setAbbrName(entity.getStorAbbr());
        return storInfo;
    }

    /**
     * 查询供货商信息列表
     * @param memCode
     * @return
     */
    public List<SuppInfo> getSuppInfoList(int memCode) {
        List<TSuppInfo> records = suppInfoService.getSuppList(memCode);

        List<SuppInfo> suppInfos = new ArrayList<>();
        records.forEach(entity->{
            SuppInfo info = buildPropertites(entity);
            suppInfos.add(info);
        });
        return suppInfos;
    }

    private SuppInfo buildPropertites(TSuppInfo entity){
        SuppInfo suppInfo = new SuppInfo();
        BeanUtils.copyProperties(entity, suppInfo);
        return suppInfo;
    }

    public SuppInfo getSuppInfo(int memCode, Integer suppCode){
        SuppInfo suppInfo = new SuppInfo();
        TSuppInfo entity = suppInfoService.getSuppInfo(memCode, suppCode);

        BeanUtil.copyPropertiesIgnoreNull(entity, suppInfo);
        return suppInfo;
    }

    /**
     * 查询类型列表
     * @return
     */
    public List<TSysCodeTbl> getPurcTypeList() {
        return sysCodeTblService.findSysCode(SysCodeTblEnum.SCT_PURC_TYPE);
    }

    /**
     * 查询采购订单状态列表
     * @return
     */
    public List<TSysCodeTbl> getPurcOrderStatList() {
        return sysCodeTblService.findSysCode(SysCodeTblEnum.SCT_PURC_ORDER_STAT);
    }

    /**
     * 查询审核订单状态列表
     * @return
     */
    public List<TSysCodeTbl> getVerfyStatList() {
        return sysCodeTblService.findSysCode(SysCodeTblEnum.SCT_VERFY_STAT);
    }

    /**
     * 查询用户状态列表
     * @return
     */
    public List<TSysCodeTbl> getUserStatList() {
        return sysCodeTblService.findSysCode(SysCodeTblEnum.SCT_USER_STAT);
    }

    /**
     * 查询机构状态列表
     * @return
     */
    public List<TSysCodeTbl> getOrganStatList() {
        return sysCodeTblService.findSysCode(SysCodeTblEnum.SCT_ORGAN_STAT);
    }

    /**
     * 查询角色状态列表
     * @return
     */
    public List<TSysCodeTbl> getRoleStatList() {
        return sysCodeTblService.findSysCode(SysCodeTblEnum.SCT_ROLE_STAT);
    }

    /**
     * 查询机构等级列表
     * @return
     */
    public List<TSysCodeTbl> getOrganLevelList() {
        return sysCodeTblService.findSysCode(SysCodeTblEnum.SCT_ORGAN_LEVEL);
    }
	
	/**
     * 根据类型查询码表
     * @return
     */
    public List<TSysCodeTbl> getSysCodeListByType(int type) {
        return sysCodeTblService.findSysCode(type);
    }

    public List<TSysCodeTbl> getMenuTypeList(){
        return sysCodeTblService.findSysCode(SysCodeTblEnum.SCT_MENU_TYPE);
    }
}